package com.yanqu.road.server.cmd.activity.jieshi;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.JieShiProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.jieshi.JieShiModule;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_JIESHI_UNLOCK_DOLL, desc = "解锁人偶")
public class JieShiUnlockDollCmd extends AbstractCommand {


    private int dollId;

    private int count;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        JieShiProto.JieShiUnlockDollReqMsg reqMsg = JieShiProto.JieShiUnlockDollReqMsg.parseFrom(packet.getBytes());
        dollId = reqMsg.getDollId();
        count = reqMsg.getCount();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(JieShiModule.class).unlockDoll(dollId, count);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            JieShiProto.JieShiUnlockDollRespMsg.Builder respMsg = JieShiProto.JieShiUnlockDollRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(Protocol.U_JIESHI_UNLOCK_DOLL, respMsg);
        }
    }
}
